// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:



//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

export enum DIRECTION {
    Down,
    Left,
    Right,
    Up
}

export enum COLOR {
    Null,
    Red,
    Blue,
    Green,
    Yellow,
    Purple,
    Orange,
    Pink,
}

export enum ShapeType {
    I = "I",
    O = "O",
    T = "T",
    S = "S",
    Z = "Z",
    J = "J",
    L = "L"
}

export interface BlockData {
    x:number;
    y:number;
    color:COLOR;
}

export interface ShapeData {
    id:number;
    type:ShapeType;
    color:COLOR;
    gridPos:cc.Vec2;
}



const {ccclass, property} = cc._decorator;

@ccclass
export default class GameConfig {

    public static readonly BIG_BLOCK_PREFAB = "prefabs/bigBlock";
    public static readonly SMALL_BLOCK_PREFAB = "prefabs/smallBlock";
 
    public static readonly BIG_BLOCK_SIZE = 30;
    public static readonly SMALL_BLOCK_SIZE = 6;
 
    //宽度固定readonly 
    public static readonly BIG_BLOCK_COL = 24;
    public static readonly BIG_BLOCK_ROW = 42; 
 
    public static readonly BEGIN_DOWN_GRID_POS = new cc.Vec2(11, 32);

    public static readonly SPEED = 1;

    public static readonly BOARD_HEIGHT = 8;

    public static readonly EVENT_NAME = {
        SHAPE_FALL_TO_BOTTOM: "SHAPE_FALL_TO_BOTTOM",
    }
 

    public static readonly SHAPES = {
        I: [[0, 0, 0, 0],[1, 1, 1, 1],[0, 0, 0, 0],[0, 0, 0, 0]],
        O: [[1, 1], [1, 1]],
        T: [[0, 1, 0], [1, 1, 1], [0, 0, 0]],
        S: [[0, 1, 1], [1, 1, 0], [0, 0, 0]],
        Z: [[1, 1, 0], [0, 1, 1], [0, 0, 0]],
        J: [[1, 0, 0], [1, 1, 1], [0, 0, 0]],
        L: [[0, 0, 1], [1, 1, 1], [0, 0, 0]]
    };

    // ========== 颜色配置 ==========
    public static readonly COLORS = {
        [COLOR.Red]: cc.color(255, 0, 0, 255),
        [COLOR.Blue]: cc.color(0, 0, 255, 255),
        [COLOR.Green]: cc.color(0, 255, 0, 255),
        [COLOR.Yellow]: cc.color(255, 255, 0, 255),
        [COLOR.Purple]: cc.color(128, 0, 128, 255),
        [COLOR.Orange]: cc.color(255, 128, 0, 255),
        [COLOR.Pink]: cc.color(0, 255, 255, 255)
    };


    /**
     * 根据颜色名称获取颜色值
     */
    static getColor(color: COLOR): cc.Color {
        return this.COLORS[COLOR[color]] || this.COLORS[COLOR.Red];
    }

    /**
     * 获取随机颜色名称
     */
    static getRandomColor(): COLOR {
        const keyList = Object.keys(this.COLORS);
        //随机选择
        const color = COLOR[keyList[Math.floor(Math.random() * keyList.length)]];
        return color;
    }

    public static getShapeMatrixLength(type:ShapeType) {
        const data = this.SHAPES[type];
        const row = data.length;
        let col = 0;
        for (let i = 0; i < row; i++) {
            if (data[i].length > col) {
                col = data[i].length;
            }
        }

        return row > col ? row : col;
    }

}
